package org.gaaidou.ptarmigan.springboot.core.common;

import java.util.function.Supplier;

public final class RetryUtil {

    public static <T, R extends Throwable> T retryWhenThrowException(Supplier<T> retryFn, R ex, int retryCount) throws R {
        for (int index = 0; index < retryCount; index++) {
            try {
                return retryFn.get();
            } catch (Exception e) {
                if (!e.getClass().equals(ex.getClass())) {
                    throw e;
                }
            }
        }
        throw ex;
    }
}
